package com.bafa.front;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bafa.dbcache.LeagueCache;
import com.bafa.exceptions.ErrorException;
import com.bafa.objects.Match;
import com.bafa.objects.PageBean;
import com.bafa.objects.season.Season;
import com.bafa.services.RetrieveServices;
import com.bafa.front.presentationbeans.ResultsListBean;
import com.bafa.front.presentationbeans.SeasonBean;
import com.bafa.front.utils.FrontUtils;
public class DisplayDivisionResultsServlet extends DaddyServlet {

	
	@Override
	public void doEvent(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ErrorException {
		
		SeasonBean season = FrontUtils.getThisSeason(request);
		request.setAttribute("RESULTS",new ResultsListBean(RetrieveServices.getDivision(request.getParameter("seasonId"),request.getParameter("divisionId")).matchArray()));
		String groupDiv="";
		if(season.isLeague()){
			groupDiv = "Division";
		}else{
			groupDiv = "Group";
		}
		PageBean pageBeanTemp = (PageBean)LeagueCache.getPages().get("results");
		pageBean = new PageBean(pageBeanTemp);
		pageBean.setPageheader(pageBean.getPageheader().replaceAll("<>",season.getName()+" "+season.getYear()+" "+groupDiv+" "+request.getParameter("divisionId")+" Results"));
	}
}
